package org.jeecg.modules.demo.zc.carCost.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.demo.zc.carCost.entity.CarCost;
import org.jeecg.modules.demo.zc.carCost.mapper.CarCostMapper;
import org.jeecg.modules.demo.zc.carCost.service.ICarCostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@DS("multi-datasource3")
@Service
public class CarCostServiceImpl extends ServiceImpl<CarCostMapper, CarCost> implements ICarCostService {

    @Autowired
    private CarCostMapper carCostMapper;

    public Integer getOrgId(String orgCode){
        return carCostMapper.getOrgId(orgCode);
    }

    public List<Integer> getparentOrgIds(Integer orgId){
        return carCostMapper.getparentOrgIds(orgId);
    }

    public IPage<CarCost> getCostSum(Page<CarCost> page,String orgIdsStr){
        List<CarCost> carCosts = carCostMapper.getCostSum(page,orgIdsStr);
        List<CarCost> carCostList = new ArrayList<>();
        for(CarCost carCost : carCosts){
            Double totalFee = carCost.getParkingFee() + carCost.getHighSpeedFee() + carCost.getTollFee() + carCost.getFuelFee() + carCost.getChargingFee() + carCost.getOtherFee() + carCost.getReportFee() + carCost.getInsureFee() + carCost.getRepairFee() + carCost.getMaintainFee() + carCost.getViolationAmount() + carCost.getMotCheckFee();
            carCost.setTotalFee(totalFee);
            carCostList.add(carCost);
        }
        return page.setRecords(carCostList);
    }


}
